/*
 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
 * Licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#include "ta_verify_key.h"
#include "ta_load_key.h"
#include <crypto_wrapper.h>

#define RSA4096_MODULE_LEN 512
#define EXE_LEN    3
#define ECC256_LEN 32
#define ALG_ECDSA  1

static ecc_pub_key_t g_ta_verify_pub_ecc_key = {
    NIST_P256,
    {
        0xE0, 0x31, 0xBB, 0x0C, 0xCE, 0xF8, 0x75, 0x67, 0x7B, 0x7C, 0xFC, 0x7E, 0x34, 0x76, 0x34, 0x24,
        0xE5, 0x21, 0x49, 0xBA, 0xCC, 0x84, 0xE4, 0xEA, 0x18, 0x55, 0x3C, 0x07, 0xB7, 0xEE, 0x6A, 0x4C
    },
    ECC256_LEN,
    {
        0x45, 0x72, 0x92, 0xD7, 0x84, 0x57, 0xDD, 0xA6, 0x25, 0x8D, 0x0E, 0x72, 0x47, 0x5C, 0xC4, 0xA4,
        0x31, 0xBA, 0xEF, 0x28, 0xD0, 0x93, 0x7D, 0x40, 0x6D, 0x74, 0x4C, 0x41, 0xAC, 0x55, 0x80, 0x96
    },
    ECC256_LEN,
};

static const rsa_pub_key_t g_ta_verify_pub_rsa_key = {
    {
        0x01, 0x00, 0x01
    },
    EXE_LEN,
    {
        0xc0, 0x7a, 0xf3, 0x03, 0xd6, 0x49, 0xdd, 0x53, 0x21, 0xe0, 0x30, 0x55, 0xe1, 0xc5, 0x92, 0xb0,
        0x1e, 0x77, 0x39, 0x3d, 0xe6, 0xa9, 0x77, 0x27, 0x62, 0xcd, 0x83, 0xbf, 0x40, 0x69, 0x43, 0xb5,
        0x2c, 0xa7, 0xed, 0xf6, 0x88, 0x77, 0xa6, 0x44, 0x02, 0xe1, 0xc7, 0x2b, 0x4e, 0xa2, 0xbc, 0x05,
        0x08, 0xe3, 0xfe, 0xfa, 0x98, 0x5c, 0xfc, 0x6e, 0x0e, 0x02, 0xcb, 0x5b, 0x48, 0xa6, 0x87, 0xb0,
        0xe6, 0xe3, 0x2b, 0xbc, 0x77, 0x16, 0xf0, 0x7f, 0x3c, 0x05, 0x6a, 0x3a, 0xf4, 0x74, 0x83, 0xa1,
        0xe8, 0xd6, 0x0b, 0x5b, 0xf0, 0x27, 0x99, 0xa3, 0x70, 0xd2, 0x02, 0x0a, 0x45, 0x27, 0xe5, 0x54,
        0xf0, 0xca, 0x89, 0x8a, 0xe3, 0x73, 0xcd, 0x84, 0x46, 0x5b, 0x8f, 0x1f, 0x5e, 0x97, 0x4e, 0x57,
        0xfd, 0xf6, 0x1d, 0xf5, 0x39, 0xbb, 0x4d, 0xe4, 0x5a, 0x66, 0x9c, 0x07, 0xac, 0xce, 0x36, 0x7d,
        0x6d, 0x84, 0x01, 0xf4, 0x25, 0x6b, 0x21, 0xf4, 0xe8, 0x9d, 0xfc, 0x21, 0xc8, 0xa9, 0x92, 0xeb,
        0x9b, 0xef, 0xcc, 0x75, 0xaa, 0xe5, 0xca, 0x61, 0x2c, 0x8b, 0x9d, 0xae, 0x8a, 0x4b, 0x0e, 0xed,
        0xe7, 0xdd, 0x9c, 0x31, 0x74, 0x35, 0x55, 0x03, 0x1a, 0xbc, 0xc9, 0xcd, 0xbc, 0x50, 0x28, 0x3e,
        0x6d, 0x52, 0xba, 0xce, 0x40, 0x4f, 0xfb, 0x35, 0xbf, 0xde, 0x91, 0x03, 0x7f, 0xca, 0x7b, 0x7a,
        0xa2, 0xa2, 0x20, 0x85, 0x56, 0x67, 0xe0, 0x58, 0x53, 0xa3, 0x53, 0x67, 0x16, 0xfb, 0xf3, 0xef,
        0x7b, 0x6e, 0x5b, 0x3d, 0x0a, 0x0d, 0x2e, 0x53, 0x30, 0x39, 0x47, 0x3c, 0xa5, 0x1f, 0x43, 0x73,
        0xc3, 0xe6, 0x08, 0x8b, 0x8f, 0xc6, 0xf5, 0xef, 0x0b, 0x76, 0xc9, 0x5d, 0x06, 0xb2, 0xe4, 0x3d,
        0x5b, 0x33, 0x30, 0x00, 0xa7, 0x85, 0x76, 0x74, 0x1a, 0xf3, 0xe9, 0xa7, 0x9d, 0x69, 0xba, 0x7c,
        0xdf, 0x73, 0xb3, 0x77, 0xc6, 0x9d, 0xc7, 0x55, 0x4e, 0x64, 0x0e, 0x22, 0xc9, 0x9a, 0x44, 0xde,
        0xec, 0x6e, 0x8a, 0xe2, 0xc5, 0x07, 0x64, 0xdc, 0x1b, 0x90, 0xf4, 0x08, 0xf8, 0xc0, 0x31, 0xa2,
        0x13, 0xde, 0xf9, 0xa1, 0x35, 0xf5, 0xbf, 0xc5, 0xce, 0x86, 0x9b, 0xf1, 0x9d, 0x3d, 0xc3, 0xa3,
        0x4e, 0x36, 0x52, 0x7c, 0x29, 0xef, 0x40, 0x31, 0xa3, 0xcd, 0x47, 0xb7, 0x1d, 0xda, 0x3e, 0xdd,
        0x9f, 0xf7, 0x1c, 0xa8, 0x65, 0xff, 0x1f, 0xc9, 0x1d, 0xb8, 0xa1, 0x7e, 0x23, 0x04, 0xfd, 0x1b,
        0x0e, 0x99, 0x7a, 0x6a, 0x05, 0x1f, 0x92, 0x2e, 0x6e, 0xc4, 0x6d, 0x56, 0xea, 0x03, 0x18, 0xbd,
        0x64, 0x38, 0xf2, 0x94, 0x0c, 0x91, 0x92, 0xbb, 0x27, 0xc6, 0xcf, 0x63, 0x6c, 0x4b, 0x9e, 0x95,
        0x99, 0x9f, 0x5a, 0xd3, 0x29, 0x9d, 0x1b, 0x7a, 0xd9, 0x5f, 0xe3, 0x0b, 0xfa, 0x93, 0x54, 0x26,
        0xa4, 0xa7, 0xca, 0x9f, 0xcb, 0xc7, 0x4c, 0x3a, 0x0a, 0x6f, 0x40, 0x23, 0x1e, 0x93, 0xe1, 0x06,
        0x0a, 0x39, 0xc4, 0xa2, 0xcc, 0x43, 0xeb, 0x34, 0xcc, 0xd6, 0x1b, 0x04, 0xcf, 0xa7, 0x74, 0x4a,
        0xb5, 0x5a, 0x46, 0x98, 0x5d, 0x20, 0xd6, 0x6b, 0x9b, 0x05, 0xbd, 0xca, 0x34, 0x92, 0xb2, 0xf9,
        0xa1, 0xd0, 0x85, 0xb4, 0x8e, 0xdb, 0xf1, 0x0d, 0x01, 0x37, 0xda, 0x67, 0x11, 0x3c, 0x0c, 0x4e,
        0xe4, 0x87, 0x41, 0xaa, 0xd2, 0xc7, 0xea, 0x22, 0x1d, 0x30, 0x3e, 0xf3, 0x1e, 0xb3, 0x28, 0x1f,
        0x95, 0x09, 0xe4, 0x5c, 0xf2, 0xfa, 0x77, 0x56, 0xd1, 0x82, 0xe5, 0x80, 0x6c, 0xb2, 0x56, 0x93,
        0x94, 0xcc, 0x44, 0xc0, 0xa9, 0x02, 0xec, 0x89, 0x55, 0x72, 0x7f, 0x8e, 0x28, 0xf6, 0x65, 0xed,
        0x7b, 0x41, 0xe7, 0xf1, 0x0b, 0xa2, 0x39, 0xbd, 0x49, 0xcf, 0x59, 0x4e, 0x8d, 0x7f, 0x88, 0x73
    },
    RSA4096_MODULE_LEN
};

static const struct ta_verify_key g_verify_key[] = {
    { PUB_KEY_256_BITS, PUB_KEY_RELEASE, &g_ta_verify_pub_ecc_key },
    { PUB_KEY_4096_BITS, PUB_KEY_RELEASE, &g_ta_verify_pub_rsa_key },
};

TEE_Result get_ta_verify_pubkey(struct ta_verify_key *key_info)
{
    return query_ta_verify_pubkey(g_verify_key, sizeof(g_verify_key) / sizeof(g_verify_key[0]), key_info);
}
